/*******************************************************************************
02_01: Make Table 1

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

Description: This code generates Table 1

*******************************************************************************/
	
	
/*******************************************************************************

I. Set labels

*******************************************************************************/

putexcel set "$tables/Table_1", replace

putexcel A1="Table 1: Total non-market work, housework, and childcare by gender and immigrant generation", bold

putexcel B2="All"
putexcel C2="Natives with Native Parents", txtwrap
putexcel D2="Immigrants", txtwrap
putexcel E2="Second-Generation Immigrants", txtwrap

putexcel A3="I. All Men and Women", bold
putexcel A4="Panel A. Women", italic
putexcel A9="Panel B. Men", italic
putexcel A14="Panel C. Women - Men", italic

putexcel A18="II. Men and Women with Children Under Age 18", bold
putexcel A19="Panel A. Women", italic
putexcel A24="Panel B. Men", italic
putexcel A29="Panel C. Women - Men", italic


/*******************************************************************************

II. Fill out table

*******************************************************************************/

**Index rows
local row = 5

**Loop through summary measures

*First, whether or not they have children
foreach group in all fam {
	
	if "`group'" == "all" {
		local g_stub ""
		}
	else if "`group'" == "fam" {
		local g_stub "& hh_numownkids!=0 & youngc<18"
		}
		
	local row_base = `row'
	
	*Then, by immigrant status
	foreach immig in all nat imm sec {
		
		local row = `row_base'
		
		if "`immig'" == "all" {
			local i_stub ""
			local col B
			}
		else if "`immig'" == "nat" {
			local i_stub "& imstat==1"
			local col C
			}
		else if "`immig'" == "imm" {
			local i_stub "& imstat==2"
			local col D
			}
		else if "`immig'" == "sec" {
			local i_stub "& imstat==3"
			local col E
			}
		
		*Women
		qui sum $nmw if female==1 `g_stub' `i_stub' [aw=newwt]
		local f_tot = r(mean)
		putexcel A`row' = "Non-Market Work"
		putexcel `col'`row' = `f_tot', nformat("#.00")
		local row = `row' + 1
		
		qui sum $hwork if female==1 `g_stub' `i_stub' [aw=newwt]
		local f_hwork = r(mean)
		putexcel A`row' = "Housework"
		putexcel `col'`row' = `f_hwork', nformat("#.00")
		local row = `row' + 1
		
		qui sum $ccare if female==1 `g_stub' `i_stub' [aw=newwt]
		local f_ccare = r(mean)
		putexcel A`row' = "Childcare"
		putexcel `col'`row' = `f_ccare', nformat("#.00")
		local row = `row' + 1
		
		qui count if female==1 `g_stub' `i_stub'
		local f_count = r(N)
		putexcel A`row' = "N"
		putexcel `col'`row' = `f_count', nformat("##,###")
		local row = `row' + 2
		
		
		*Men
		qui sum $nmw if female==0 `g_stub' `i_stub' [aw=newwt]
		local m_tot = r(mean)
		putexcel A`row' = "Non-Market Work"
		putexcel `col'`row' = `m_tot', nformat("#.00")
		local row = `row' + 1
		
		qui sum $hwork if female==0 `g_stub' `i_stub' [aw=newwt]
		local m_hwork = r(mean)
		putexcel A`row' = "Housework"
		putexcel `col'`row' = `m_hwork', nformat("#.00")
		local row = `row' + 1
		
		qui sum $ccare if female==0 `g_stub' `i_stub' [aw=newwt]
		local m_ccare = r(mean)
		putexcel A`row' = "Childcare"
		putexcel `col'`row' = `m_ccare', nformat("#.00")
		local row = `row' + 1
		
		qui count if female==0 `g_stub' `i_stub'
		local m_count = r(N)
		putexcel A`row' = "N"
		putexcel `col'`row' = `m_count', nformat("##,###")
		local row = `row' + 2
		
		
		*Difference
		local diff = `f_tot' - `m_tot'
		putexcel A`row' = "Non-Market Work"
		putexcel `col'`row' = `diff', nformat("#.00")
		local row = `row' + 1
		
		local diff = `f_hwork' - `m_hwork'
		putexcel A`row' = "Housework"
		putexcel `col'`row' = `diff', nformat("#.00")
		local row = `row' + 1
		
		local diff = `f_ccare' - `m_ccare'
		putexcel A`row' = "Childcare"
		putexcel `col'`row' = `diff' , nformat("#.00")
		
		}
		
	local row = `row' + 3
	
	}
